Function.RegisterNamespace("Test.System");

[Fixture]
Test.System.Environment=function(){
    [Fixture]
    function Environment(){
        [Fact]
        function InitializesStrategyManager(){
            var expected=System.Script.Strategy.StrategyManager;
        
            var actual=System.Environment.Strategies;
            
            Assert.True(Object.IsType(expected,actual));
        }
    }
    
    [Fixture]
    function Exit(){
        [Fact]
        function CallsExitOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Exit:function(){
                    actual=true;
                }};
            };
            var actual=false;
            
            System.Environment.Exit();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.True(actual);
        }

        [Fact]
        function PassesErrorCodeToExitOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Exit:function(errorCode){
                    actual=errorCode;
                }};
            };
            var actual=null;
            var expected="expected";
            
            System.Environment.Exit(expected);
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ReturnsValueFromExitOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Exit:function(){
                    return expected;
                }};
            };
            var actual=null;
            var expected="expected";
            
            var actual=System.Environment.Exit();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }
    }
    
    [Fixture]
    function GetParameters(){
        [Fact]
        function CallsGetParametersOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {GetParameters:function(){
                    actual=true;
                }};
            };
            var actual=false;
            
            System.Environment.GetParameters();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.True(actual);
        }

        [Fact]
        function ReturnsValueFromGetParametersOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {GetParameters:function(){
                    return expected;
                }};
            };
            var actual=null;
            var expected="expected";
            
            var actual=System.Environment.GetParameters();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        
    }
    
    [Fixture]
    function GetWorkingDirectory(){
        [Fact]
        function CallsGetWorkingDirectoryOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {GetWorkingDirectory:function(){
                    actual=true;
                }};
            };
            var actual=false;
            
            System.Environment.GetWorkingDirectory();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.True(actual);
        }

        [Fact]
        function ReturnsValueFromGetWorkingDirectoryOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {GetWorkingDirectory:function(){
                    return expected;
                }};
            };
            var actual=null;
            var expected="expected";
            
            var actual=System.Environment.GetWorkingDirectory();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        
    }
    
    [Fixture]
    function Write(){
        [Fact]
        function CallsWriteOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Write:function(){
                    actual=true;
                }};
            };
            var actual=false;
            
            System.Environment.Write();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.True(actual);
        }

        [Fact]
        function ReturnsValueFromWriteOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Write:function(){
                    return expected;
                }};
            };
            var actual=null;
            var expected="expected";
            
            var actual=System.Environment.Write();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function PassesMessageToWriteOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Write:function(message){
                    actual=message;
                }};
            };
            var actual=null;
            var expected="expected";
            
            System.Environment.Write(expected);
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function PassesAllMessagesToWriteOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {Write:function(){
                    actual=Array.prototype.slice.call(arguments,0);
                }};
            };
            var actual=null;
            var expected=["expected1","expected2","expected3"];
            
            System.Environment.Write(expected[0],expected[1],expected[2]);
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

    }    
    
    [Fixture]
    function WriteError(){
        [Fact]
        function CallsWriteErrorOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {WriteError:function(){
                    actual=true;
                }};
            };
            var actual=false;
            
            System.Environment.WriteError();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.True(actual);
        }

        [Fact]
        function ReturnsValueFromWriteErrorOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {WriteError:function(){
                    return expected;
                }};
            };
            var actual=null;
            var expected="expected";
            
            var actual=System.Environment.WriteError();
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function PassesMessageToWriteErrorOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {WriteError:function(message){
                    actual=message;
                }};
            };
            var actual=null;
            var expected="expected";
            
            System.Environment.WriteError(expected);
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function PassesAllMessagesToWriteErrorOnStrategy(){
            var strategyGet=System.Environment.Strategies.Get;
            System.Environment.Strategies.Get=function(){
                return {WriteError:function(){
                    actual=Array.prototype.slice.call(arguments,0);
                }};
            };
            var actual=null;
            var expected=["expected1","expected2","expected3"];
            
            System.Environment.WriteError(expected[0],expected[1],expected[2]);
            System.Environment.Strategies.Get=strategyGet;
            
            Assert.Equal(expected,actual);
        }        

    }
}